<template>
    <div>
        <Dialog v-model="dialogVisible1" title="重新进入初筛" width="420">
            <div class="message_p">
                <el-form ref="ruleFormRef" :model="state.form" :rules="rules" label-width="120px" label-position="top">
                    <el-form-item label="职位" prop="positionRegistrationId">
                        <el-select v-model="state.form.positionRegistrationId" clearable placeholder="请选择职位"
                            style="width: 100%">
                            <el-option v-for="item in state.positionOptions" :key="item.id" :label="item.positionName"
                                :value="item.id" />
                        </el-select>
                    </el-form-item>
                    <div class="flex jcfe aic" style="width: 100%;">
                        <el-button @click="DialogClose">取消</el-button>
                        <el-button type="primary" @click="submitForm(ruleFormRef)">确定</el-button>
                    </div>
                </el-form>
            </div>
        </Dialog>
    </div>
</template>
<script lang="ts" setup>
import { positionListAll } from "@/api/recruit/index"
import type { FormInstance, FormRules } from 'element-plus'
import { dictSect } from "@/utils/dictUnit"
import { ref, reactive } from 'vue'
import { Dialog } from '@/components/Dialog'
import { ElButton } from 'element-plus'
const dialogVisible1 = ref(false)
const loading = ref(false)
const emit = defineEmits(['refashClick'])
const props = defineProps({
    refuseData: {
        type: Object,
        default: () => {
            return {}
        }
    }

})
interface RuleForm {
    positionRegistrationId: string

}
const ruleFormRef = ref<FormInstance>()
const rules = reactive<FormRules<RuleForm>>({
    positionRegistrationId: [{ required: true, message: '请选择职位', trigger: 'blur' }],

})
const state = reactive({
    form: {
        content: ""
    } as any,
    positionOptions: [] as any,
})
const options1: any = dictSect("resume_label")

const DialogOpen = () => {
    dialogVisible1.value = true
}
const DialogClose = () => {
    dialogVisible1.value = false
}

const submitForm = async (formEl: FormInstance | undefined) => {
    if (!formEl) return
    await formEl.validate((valid, fields) => {
        if (valid) {
            emit('refashClick', state.form)
        } else {
            console.log('error submit!', fields)
        }
    })
}
// 暴露方法
defineExpose({
    DialogOpen,
    DialogClose
})
const positionListAllApi = async () => {
    await positionListAll().then(res => {
        state.positionOptions=[]
        // console.log("全部职位", res);
        res.data.forEach(element => {
            if (element.status == 2) {
                state.positionOptions.push(element)
            }
        });
        // state.positionOptions = res.data
    })
}
positionListAllApi()
</script>
<style lang="less">
.el-dialog__header {
    padding: 10px;
    border-bottom: 1px solid #D8D8D8;
}

.el-dialog__body {
    padding: 20px;
}
</style>
<style lang="less" scoped>
.message_p {
    padding: 0px 10px 20px 10px;
}

.el-button {
    margin-top: 20px;
    width: 134px;
    height: 40px;
}
</style>